package com.example.day1.BIM;

import androidx.appcompat.app.AppCompatActivity;

import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.widget.ImageView;
import android.widget.TextView;

import com.example.day1.R;

public class BIMHealthActivity2 extends AppCompatActivity {
    TextView resultBim,resultState,resultHeight,resultWeight;
    ImageView iv;
    private static final String TAG = "BimResultActivity";
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_bimhealth2);
        Intent intent=getIntent();
        String sex = intent.getStringExtra("sex");
        double height = Double.parseDouble(String.valueOf(intent.getDoubleExtra("height",0)));
        double weight = Double.parseDouble(String.valueOf(intent.getDoubleExtra("weight",0)));



        Log.d(TAG, "height: "+height);
        Log.d(TAG, "weight: "+weight);

        Log.d(TAG, "sex "+sex);
        resultBim=findViewById(R.id.bim_result_code);
        resultHeight=findViewById(R.id.bim_result_height);
        resultWeight=findViewById(R.id.bim_result_weight);
        resultState=findViewById(R.id.bim_state);
        iv=findViewById(R.id.bim_result_iv);
        double code=weight/(height*height);
        Log.d(TAG, "code "+code);
        String healthState="";
        if (sex.equals("男")) {
            if (code < 18) {
                healthState="偏瘦状态";
                iv.setImageResource(R.mipmap.bmi_1);
            } else if (code < 22) {
                healthState="健康状态";
                iv.setImageResource(R.mipmap.bmi_2);
            } else if (code < 25) {
                healthState="肥胖状态";
                iv.setImageResource(R.mipmap.bmi_3);
            }else {
                healthState="重度肥胖";
                iv.setImageResource(R.mipmap.bmi_4);
            }
        }else {
            if (code < 16) {
                healthState="偏瘦状态";
                iv.setImageResource(R.mipmap.bmi_1);
            }else if (code < 20) {
                healthState="健康状态";
                iv.setImageResource(R.mipmap.bmi_2);
            } else if (code < 23) {
                healthState="肥胖状态";
                iv.setImageResource(R.mipmap.bmi_3);
            }else {
                healthState="重度肥胖";
                iv.setImageResource(R.mipmap.bmi_4);
            }

        }
        resultBim.setText(String.valueOf(code));
        resultState.setText(healthState);
        resultWeight.setText(String.valueOf(weight)+"KG");
        resultHeight.setText(String.valueOf(height)+"M");

    }
}